package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import com.shaoshaohuo.app.R;

import java.util.List;

/**
 * Created by Administrator on 2017/6/30.
 */

public class DialogListViewAdapter extends BaseAdapter {
    private Context context;
    private List<String> data;
    //    private int selectPosition = -1;
    private int selectPosition = -1;

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
        notifyDataSetChanged();
    }

    public DialogListViewAdapter(Context context, List<String> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DialogViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.dialog_listview_item, parent, false);
            holder = new DialogViewHolder();
            holder.dialog_listView_imagView = (RadioButton) convertView.findViewById(R.id.dialog_listView_imagView);
            holder.dialog_listView_text = (TextView) convertView.findViewById(R.id.dialog_listView_text);
            convertView.setTag(holder);
        } else {
            holder = (DialogViewHolder) convertView.getTag();
        }
        holder.dialog_listView_text.setText(data.get(position));
        if (selectPosition == position) {
            holder.dialog_listView_imagView.setChecked(true);
        } else {
            holder.dialog_listView_imagView.setChecked(false);
        }

        return convertView;
    }

    class DialogViewHolder {
        TextView dialog_listView_text;
        RadioButton dialog_listView_imagView;
    }
}
